package unit_test;

import static org.junit.Assert.*;
import logic.CommandHandler;

import org.junit.Test;

import common.Task;
import common.TaskStatus;
import common.TaskType;

/**
 * Tester for TaskCollision (soft collision)
 * 
 */

//@author A0088498A
public class TaskSoftCollisionTest {
	@Test
	public void nullCollision() {
		Task task = null, otherTask = null;

		// 2 null Tasks
		assertFalse(Task.checkTimeCollision(task, otherTask));
	}

	@Test
	public void overlappingTasksWithBlock() {
		CommandHandler handler = new CommandHandler();
		Task task = null, otherTask = null;

		// 2 overlapping timed Tasks, one of them is blocked
		task = new Task("Task1", TaskType.timed, "", handler.getDateTime("21/03/2014 0000"), handler.getDateTime("23/03/2014 2359"), TaskStatus.undone);
		otherTask = new Task("Task2", TaskType.timed, "", handler.getDateTime("20/03/2014 0000"), handler.getDateTime("22/03/2014 2359"), TaskStatus.block);
		assertTrue(Task.checkTimeCollision(task, otherTask));
	}

	@Test
	public void touchingTaskWithBlock() {
		CommandHandler handler = new CommandHandler();
		Task task = null, otherTask = null;

		// 2 "touching" timed Tasks, one of them is blocked
		task = new Task("Task1", TaskType.timed, "", handler.getDateTime("21/03/2014 0000"), handler.getDateTime("23/03/2014 0000"), TaskStatus.undone);
		otherTask = new Task("Task2", TaskType.timed, "", handler.getDateTime("23/03/2014 0000"), handler.getDateTime("25/03/2014 2359"), TaskStatus.block);
		assertFalse(Task.checkTimeCollision(task, otherTask));
	}

	@Test
	public void overlappingTaskWithoutBlock() {
		CommandHandler handler = new CommandHandler();
		Task task = null, otherTask = null;

		// 2 overlapping timed Tasks, non blocked
		task = new Task("Task1", TaskType.timed, "", handler.getDateTime("21/03/2014 0000"), handler.getDateTime("23/03/2014 2359"), TaskStatus.undone);
		otherTask = new Task("Task2", TaskType.timed, "", handler.getDateTime("20/03/2014 0000"), handler.getDateTime("22/03/2014 2359"), TaskStatus.undone);
		assertTrue(Task.checkTimeCollision(task, otherTask));
	}

	@Test
	public void nonTimedTask() {
		CommandHandler handler = new CommandHandler();
		Task task = null, otherTask = null;

		// timed Task with non-timed Task
		task = new Task("Task1", TaskType.timed, "", handler.getDateTime("21/03/2014 0000"), handler.getDateTime("23/03/2014 2359"), TaskStatus.block);
		otherTask = new Task("Task2", TaskType.floating, "", null, null, TaskStatus.undone);
		assertFalse(Task.checkTimeCollision(task, otherTask));
	}

}
